<?php


namespace app\api\controller\v1;


use app\api\validate\IDCollection;
use app\api\validate\IDMustBeInt;
use app\lib\exception\ThemeException;
use think\Controller;
use app\api\model\Theme as ThemeModel;

class Theme extends Controller
{
    /**
     * @url /theme?ids=id1,id2,id3,...
     */
    public function getSimpleList($ids='') {
        (new IDCollection()) -> goCheck();
        $ids = explode(',', $ids);
        $result = ThemeModel::with('topicImg,headImg')->select($ids);
        if (!$result) {
            throw new ThemeException();
        }
        return json($result);
    }

    /**
     * @param $id
     * @url  theme/:id
     */
    public function getComplexoNE($id) {
        (new IDMustBeInt()) -> goCheck();
        $theme = ThemeModel::getThemeWithProductsById($id);
        if (!$theme) {
            throw new ThemeException();
        }
        return json($theme);
    }
}